//
//  ZJlockRoomVC.m
//  这家测试项目
//
//  Created by IOS_DEVELOPER on 2017/6/15.
//  Copyright © 2017年 陈志凌. All rights reserved.
//

#import "ZJlockRoomVC.h"
#import "ZJZJlockRoomView.h"
@interface ZJlockRoomVC (){
     NSInteger type;
}

@property (weak, nonatomic) IBOutlet UIScrollView *scrollview;
@property (strong, nonatomic) ZJZJlockRoomView *lockRoomView;
@property (strong, nonatomic)UIAlertController *alertController;
@end

@implementation ZJlockRoomVC

-(ZJZJlockRoomView *)lockRoomView{
    if (!_lockRoomView) {
        self.lockRoomView = [[[NSBundle mainBundle] loadNibNamed:@"ZJlockRoomVC" owner:self options:nil] lastObject];
    }
    return _lockRoomView;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.title = self.strTitle?:@"抢房成功";

    self.lockRoomView.model = self.model;
    self.lockRoomView.topimg.image = [UIImage imageWithContentsOfFile:[Utils imgPath:@"zxgf_pic_cg@3x.png"]];
    self.scrollview.contentSize = CGSizeMake(0, SCREEN_HEIGHT + 100);
    self.scrollview.backgroundColor = [UIColor clearColor];
    self.view.backgroundColor = self.lockRoomView.backgroundColor;
    self.lockRoomView.frame = CGRectMake(0, 0, self.scrollview.width, self.view.height + 100);
    [self.lockRoomView.topBtn setTitleColor:[Utils colorWithHexString:allConstHexColor] forState:0];
    
    if (SCREEN_WIDTH <= 320) {
        self.lockRoomView.rightImg.sd_layout.topSpaceToView(self.lockRoomView.bgView, 27).rightSpaceToView(self.lockRoomView.bgView, 41).widthIs(20).heightIs(20);
    }
    self.lockRoomView.rightImg.image = [UIImage imageWithContentsOfFile:[Utils imgPath:@"tqbm_icon_yjh@3x.png"]];
    
    self.lockRoomView.mainTitle.text = self.model.house?:[NSString stringWithFormat:@"%@%@ %@%@ %@(室)",_model.building_name?:@"",_model.building_unit?:@"",_model.unit_name?:@"",_model.unit_unit?:@"",_model.house_name];
    
    self.lockRoomView.JianMianTitle.text = _model.house_area;
    self.lockRoomView.TaoNeiTitle.text = _model.actual_area;
    self.lockRoomView.HuXingTitle.text = _model.layout;
    self.lockRoomView.bgView.layer.shadowColor = RGB(235, 235, 235).CGColor;;
    self.lockRoomView.bgView.layer.shadowOpacity = 0.8f;
    self.lockRoomView.bgView.layer.shadowOffset = CGSizeMake(0,0.1);
    
    if ([_model.actual_area integerValue] <=0) {
        self.lockRoomView.TaoNeiTitle.hidden = YES;
        self.lockRoomView.leftTaoNeiLabel.hidden = YES;
        self.lockRoomView.bgView.sd_layout.leftSpaceToView(self.lockRoomView, 12).rightSpaceToView(self.lockRoomView, 12).topSpaceToView(self.lockRoomView, 120).heightIs(298);
        self.lockRoomView.bottomLeftImg.sd_layout.leftSpaceToView(self.lockRoomView, 16).topSpaceToView(self.lockRoomView.bgView, 8).heightIs(15).widthIs(15);
        self.lockRoomView.bottomTitle.sd_layout.leftSpaceToView(self.lockRoomView.bottomLeftImg, 8).topSpaceToView(self.lockRoomView.bgView, 5).rightSpaceToView(self.lockRoomView, 16).heightIs(21);
        self.lockRoomView.bottomView.hidden = YES;
    }
    [self.scrollview addSubview:self.lockRoomView];
    NSArray *arr = [ZJRoomModel rooms];
    
    BOOL ok = [ZJRoomModel removeRoomModel:arr];
    
    if (ok) {
        NSLog(@"抢房条已清空");
    }
    
    if ([self.userModel.has_buy_house integerValue] != 1) {
        [HUD showLoading:@"正在更新缓存数据..."];
        self.userModel.has_buy_house = @"1";
        self.userModel.house_buy = self.model.keyValues;
        SYN_USER(self.userModel);
        NSDictionary *parameter = [LRNetwork requestParameter:@{}];
        NSString *url = [LRNetwork requestURL:@"cgi/main.php"];
        
        [LRNetwork netRequestPOSTWithRequestURL:url withParameter:parameter withReturnValeuBlock:^(id returnValue) {

            [HUD showSucceedMsg:@"购买成功"];
            self.userModel = [ZJUserModel mj_objectWithKeyValues:returnValue[@"user"]];
            SYN_USER(self.userModel);
        } withErrorCodeBlock:^(NSInteger errorCode, NSString *errorMessage) {
            [HUD hide];
            NSLog(@"error:%@",errorMessage);
        } withFailureBlock:^{
        }];
        [HUD hide];

    }

    
    BaseNavigationController * nvc = self.navigationController;
    if (self.isBack) {
        nvc.bakcRootView = NO;
    }else{
        nvc.bakcRootView = YES;
    }
}


@end
